package com.homedo.microservice.open.service.gateway.zuul.conf;

import com.homedo.microservice.open.service.gateway.bean.constant.CommonConstant;
import com.homedo.microservice.open.service.gateway.util.ApplicationContextUtil;
import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicLongProperty;
import com.netflix.config.DynamicPropertyFactory;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Data
public class ZuulCommonConf {
    @Value("${" + CommonConstant.APPLICATION_NAME + "}")
    private String applicationName;

    @Value("${" + CommonConstant.ZUUL_FILTER_PRE_PATH + "}")
    private String zuulFilterPrePath;
    @Value("${" + CommonConstant.ZUUL_FILTER_ROUTE_PATH + "}")
    private String zuulFilterRoutePath;
    @Value("${" + CommonConstant.ZUUL_FILTER_POST_PATH + "}")
    private String zuulFilterPostPath;
    @Value("${" + CommonConstant.ZUUL_FILTER_ERROR_PATH + "}")
    private String zuulFilterErrorPath;
    @Value("${" + CommonConstant.Zuul_FILTER_CUSTOM_PATH + ":}")
    private String zuulFilterCustomPath;


    private DynamicBooleanProperty zuulFilterPollerEnabled = DynamicPropertyFactory.getInstance().getBooleanProperty(CommonConstant.ZUUL_FILTER_POLLER_ENABLED, true);
    private DynamicLongProperty zuulFilterPollerInterval = DynamicPropertyFactory.getInstance().getLongProperty(CommonConstant.ZUUL_FILTER_POLLER_INTERVAL, 30000L);

    private DynamicBooleanProperty zuulUseCanaryFilters = DynamicPropertyFactory.getInstance().getBooleanProperty(CommonConstant.ZUUL_USE_CANARY_FILTERS, false);

    private DynamicBooleanProperty applicationLogDetail = DynamicPropertyFactory.getInstance().getBooleanProperty(CommonConstant.APPLICATION_LOG_DETAIL, false);

    private DynamicLongProperty routeConfUpdateInterval = DynamicPropertyFactory.getInstance().getLongProperty(CommonConstant.ROUTE_CONF_UPDATE_INTERVAL, 6000L);

    public static ZuulCommonConf get() {
        return ApplicationContextUtil.getApplicationContext().getBean(ZuulCommonConf.class);
    }

}
